<?php


/*
 * Created on Apr 26, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */

session_start();

if (isset ($_SESSION['userid']) && $_SESSION['level'] == '2') {
	//do nothing
} else {
	header('location: login.php');
	exit ();
}
?>

<html>
	<head>
		<title>Manage User</title>
	</head>
	<body>
	<?php
		$conn = mysql_connect('localhost', 'root', 'vertrigo') or die('can not connect to server');
		mysql_select_db('iblog', $conn);
		$sql = "select * from user";
		$query = mysql_query($sql);
		if (mysql_num_rows($query)==0){
			echo "<h1>No data</h1>";
		}else{				
	?>
		<table align="center" width="400" border="1">
			<tr>
				<th>STT</th>
				<th>Username</th>
				<th>Level</th>
				<th>Edit</th>
				<th>Delete</th>
			</tr>
	<?php
		$stt = 0;
		while($row = mysql_fetch_array($query)){
			$stt++;
			echo "<tr>";
			echo "<td>". $stt ."</td>";
			echo "<td>". $row['username'] ."</td>";
			if ($row['level'] == '1'){
				echo "<td>Member</td>";
			}else if ($row['level'] == '2'){
				echo "<td>Admin</td>";
			}
			echo "<td><a href='edit_user.php?userid=". $row['id'] ."'>Edit</a></td>";
			echo "<td><a href='delete_user.php?userid=". $row['id'] ."'>Del</a></td>";
			echo "</tr>";
		}//end while
		
		mysql_close($conn);
		}//end else
	?>
		</table>
	</body>
</html>
